package edu.vt.sdm.tcga.navigator;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.navigator.CommonActionProvider;
import org.eclipse.ui.navigator.ICommonActionConstants;
import org.eclipse.ui.navigator.ICommonActionExtensionSite;
import org.eclipse.ui.navigator.ICommonViewerSite;
import org.eclipse.ui.part.ViewPart;

public class ActionProvider extends CommonActionProvider {
	private class MyAction extends Action implements ISelectionChangedListener {

		@Override
		public void selectionChanged(SelectionChangedEvent event) {
			IViewPart vp = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("edu.vt.sdm.tcga.View.HeatMap");			
			String strTemp = vp.getTitle();
		}
		
	}
	
	private MyAction propertyAction;

	
	private ICommonViewerSite viewSite;

	public void init(ICommonActionExtensionSite site) {

		super.init(site);

		viewSite = site.getViewSite();

		propertyAction = new MyAction();
		/*{

			@Override
			public void run() {

				IStructuredSelection selection = (IStructuredSelection) viewSite

				.getSelectionProvider().getSelection();

				Object firstElement = selection.getFirstElement();

				if (firstElement instanceof ParentBean) {

					ParentBean selectedNode = (ParentBean) firstElement;

					// MessageDialog.openInformation(viewSite.getShell(),
					//
					// "Property", getAllAttributes(selectedNode));

				}

			}

		};*/
		
		site.getStructuredViewer().addSelectionChangedListener(propertyAction);
	}
	
    /* (non-Javadoc)
     * @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars)
     */
    @Override
    public void fillActionBars(IActionBars actionBars) {
        super.fillActionBars(actionBars);
        // forward doubleClick to doubleClickAction
        actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN,
        		propertyAction);
    }	
}
